﻿@model RepertorySystem.Models.InsertOrderList
@Scripts.Render("~/bundles/jquery")
@{
    ViewBag.Title = "Edit";
}

<h2>修改订单 <span class="glyphicon glyphicon-cog" style="color: rgb(69, 63, 63);"></span></h2>


@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    
    <div class="form-horizontal">
        <h4>订单详情</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        @Html.HiddenFor(model => model.ID)

        <div class="form-group">
            @Html.LabelFor(model => model.Supplier, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Supplier, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Supplier, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Book_Id, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                <input class="form-control" id="book_Id" />
                <input name="Book_Id" type="hidden" id="input_bookid"/>
                @{
                    //获取端口
                    IServiceProvider provider = (IServiceProvider)HttpContext.Current;
                    HttpWorkerRequest request = (HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest));
                    var port = HttpContext.Current.Request.Url.Port;

                }
                @if (@Html.DisplayFor(model => model.Book_Id) != null) {
                    <script type="text/javascript">
                        var bookId = @Html.DisplayFor(model => model.Book_Id);
                        $.ajax({
                            url: "http://localhost:"+@port+"/api/Books/"+bookId,
                            type:"get",
                            success: function (result) {
                                $("#book_Id").val(result.Name);
                                $("#input_bookid").val(bookId);
                            },
                            error: function (msg) {
                                console.log(msg);
                            }

                        });

                    </script>
                }
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Number, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Number, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Number, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Time, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Time, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Time, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Price, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Price, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Price, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.State, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                <select id="order_State" class="form-control" data-val="true" data-val-number="字段 必须是一个数字。" name="State" style="width:180px"></select>

                <script type="text/javascript">
                    var sta = @Html.DisplayFor(model => model.State);
                    $(function () {
                        if(sta == 0){
                            $("#order_State").append("<option value='0'>未完成</option>");
                            $("#order_State").append("<option value='1'>已完成</option>");
                        }else{
                            $("#order_State").append("<option value='1'>已完成</option>");
                            $("#order_State").append("<option value='0'>未完成</option>");
                        }
                    });
                </script>
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-1">
                <input type="submit" value="保存" class="btn btn-default" />
            </div>
            <div class="col-md-2">
                @Html.ActionLink("返回订单列表", "Index", null, new { @class = "btn btn-default" })
            </div>
        </div>
    </div>
}

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}
